package com.example.spring_project.config;

import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Author: 郑国荣
 * @Date: 2023-07-22-16:56
 * @Description: swagger配置类
 * 访问地址：<a href="http://localhost:8090/swagger-ui/index.html">...</a>
 */

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean //配置docket以配置Swagger具体参数
    public Docket productApi() {
        return new Docket(DocumentationType.SWAGGER_2) //文档类型（swagger2）
                .apiInfo(apiInfo())  //设置api文档信息
                .select()  //构建api选择器
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))  //只显示添加了ApiOperation注解的方法
                .paths(PathSelectors.any()) //api选择器选择api的路径
                .build();   //创建文档
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("swagger和springBoot整合").description("图书管理系统的API文档") //设置文档的标题和描述
                .version("1.0").build(); //设置文档的版本信息
    }

}
